//
//  AddCourseViewController.m
//  TraineeManagementSystem
//
//  Created by Dhanashree Bodas on 28/01/15.
//  Copyright (c) 2015 Dhanashree Bodas. All rights reserved.
//

#import "AddCourseViewController.h"
#import "CourseTable.h"

@interface AddCourseViewController ()

@end

@implementation AddCourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)nameEntered:(id)sender {
    [self resignFirstResponder];
}
- (IBAction)platformEntered:(id)sender {
    [self resignFirstResponder];
}

- (IBAction)cancelPressed:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)addPressed:(id)sender {
    CourseTable *c=[[CourseTable alloc]init];
    
    if([self.coursename.text isEqualToString:@""] | [self.platform.text isEqualToString:@""] | [self.description1.text isEqualToString:@""])
    {
    
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Validation" message:@"Fields cannot be empty" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        
        [alert show];
    
    
    }
    else
    {
    int i= [c addCourse:self.coursename.text andplatform:self.platform.text anddescription:self.description1.text];
    if(i==1)
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Add Course" message:@"Course added successfully!!!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else
        NSLog(@"Error cannot add");
    
    }
    
}
@end
